package club.kunlingou.dsc.httpclient;

import java.util.Date;

import com.alibaba.fastjson.JSONObject;

import club.kunlingou.dsc.common.util.HttpsClient;
import club.kunlingou.dsc.common.util.HttpsClientUtil;

public class HttpClientTest {

	public static void main(String[] args) {
//		System.out.println(System.currentTimeMillis());
//		System.out.println(new Date().getTime());
//		getSignInfoFromOffice("3945", new Date());

//		
		JSONObject content = new JSONObject();
		content.put("q", "您好");

		try {
			String doPost = HttpsClient
					.configure("http://data.zz.baidu.com/urls?site=https://www.kunlingou.club&token=VvBsRinQ2JJttYrO")
					.addRequestProperty("User-Agent", "curl/7.12.1")
					.addRequestProperty("Host", "data.zz.baidu.com")
					.addRequestProperty("User-Agent", "curl/7.12.1 ")
					.doPost("");
//			String doPost = HttpsClientUtil.doPost("https://fanyi-api.baidu.com/api/trans/vip/translate", "");
			System.out.println(doPost);
		} catch (Exception e) {
			e.printStackTrace();
		}

//		com.alibaba.fastjson.JSONObject inputJson = new com.alibaba.fastjson.JSONObject();
//		inputJson.put("loginUserId", "4449");
//		inputJson.put("signTime", DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
//		inputJson.put("signType", "m-sign");
//		inputJson.put("longitude", 1000.00);
//		inputJson.put("latitude", 20.00);
//		inputJson.put("address", "测试地址");
//		inputJson.put("deviceUuid", "113212341234124");
//		inputJson.put("type", "4-3");
//		saveSignInfoToOffice(inputJson);
	}

	/**
	 * 查询打卡信息-查询办公网数据
	 * 
	 * @param loginUser
	 * @param date
	 * @return
	 */
	private static com.alibaba.fastjson.JSONObject getSignInfoFromOffice(String loginUserId, Date date) {
		// 调用YJT_AMS接口取得考勤打卡记录
//		String url = "http://111.204.211.205:8380/RunErpSystem/getRealSign.action";
		String url = "https://111.204.211.198:8180/RunErpSystem/getRealSign.action";
		StringBuffer sb = new StringBuffer();
		String reqUr = null;
		if (url != null && !url.equals("")) {
			sb.append(url);
			sb.append("?userId=");
			sb.append(loginUserId);
			sb.append("&date=");
			sb.append("2019-12-26");
			reqUr = sb.toString();
		}
		String processResult = null;
		String responseJson = null;
		com.alibaba.fastjson.JSONObject result = null;
		try {
			System.out.println("----------startGet----------;url:" + reqUr);
			processResult = HttpsClientUtil.doGet(reqUr);
			if (processResult.indexOf("SUCCESS") != -1) {
				processResult = processResult.replace("\\\"", "\"").replaceFirst("\"", "");
				if (processResult.endsWith("\"")) {
					processResult = processResult.substring(0, processResult.length() - 1);
				}
				result = com.alibaba.fastjson.JSONObject.parseObject(processResult.replace("\\", ""));
				System.out.println(processResult);
			} else {
				System.out.println("----------EndGet----------;res:" + responseJson);
			}
		} catch (Exception e) {
			System.out.println("----------EndGet----------;resFail:");
		}
		return result;
	}

	private static String saveSignInfoToOffice(com.alibaba.fastjson.JSONObject inputJson) {
		// 调用YJT_AMS接口保存考勤打卡记录
		String url = "http://111.204.211.205:8380/RunErpSystem/saveRealSign.action";
//		String url = "https://111.204.211.198:8180/RunErpSystem/saveRealSign.action";
		StringBuffer sb = new StringBuffer();
		String reqUr = null;
		if (url != null && !url.equals("")) {
			sb.append(url);
			sb.append("?loginUserId=");
			sb.append(inputJson.getString("loginUserId"));
			sb.append("&signTime=");
			sb.append(inputJson.getString("signTime"));
			sb.append("&signType=");
			sb.append(inputJson.getString("signType"));
			sb.append("&longitude=");
			sb.append(inputJson.getString("longitude"));
			sb.append("&latitude=");
			sb.append(inputJson.getString("latitude"));
			sb.append("&address=");
			sb.append(inputJson.getString("address"));
			sb.append("&deviceUuid=");
			sb.append(inputJson.getString("deviceUuid"));
			sb.append("&type=");
			sb.append(inputJson.getString("type"));
			reqUr = sb.toString();
		}
		String responseJson = null;
		try {
			System.out.println("----------startSave----------;url:" + reqUr);
			String processResult = HttpsClientUtil.doGet(reqUr);
			if (processResult.indexOf("SUCCESS") != -1) {
				System.out.println(processResult);
//				responseJson = constructResponseJson("SUCCESS", "操作成功");
			} else {
//				responseJson = constructResponseJson("FAIL", "操作失败");
			}
			System.out.println("----------EndGet----------;res:" + responseJson);
		} catch (Exception e) {
			System.out.println("----------EndGet----------;resFail:");
			e.printStackTrace();
//			logger.error("保存考勤打卡记录到AMS失败，exception="+ e.getMessage());
//			responseJson = constructResponseJson("FAIL", "操作失败");
		}
		return responseJson;
	}
}
